<template>
    <view>
        <!-- pages/goodsDetail/index.wxml -->
        <!-- 头部 -->
        <navber id="head-navber" :navbarData="navbarData"></navber>
        <!-- 详情 -->
        <view class="goodsDetail">
            <view class="goodsDetail-img">
                <view class="goodsDetail-img-list">
                    <image :src="item" @tap="previewImage($event, { src: item })" :data-src="item" mode="widthFix" v-for="(item, index) in banner_detail" :key="index"></image>
                </view>
            </view>
        </view>
        <view class="end"></view>
    </view>
</template>

<script>
import navber from '@/components/navber/index';
// pages/imgview/index.js
const Config = require('../../config/index.js');

const Api = require('../../api/index.js');

const app = getApp();
export default {
    components: {
        navber
    },
    data() {
        return {
            navbarData: {
                title: '详情',
                //顶部标题
                is_show_bottom: true,
                //显示背景图
                bac_img: '/assets/imgs/navbar/navbar_bg1' //显示背景图片
            },
            //导航栏
            imgUrl: Config.imgUrl,
            //图片url
            id: 0,
            //商品id
            banner_detail: []
        };
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let id = options.id;
        this.setData({
            id: id
        });
        this.getDetail();
    },
    methods: {
        previewImage: function (e, _dataset) {
            
            if (!e.currentTarget) {
                if (_dataSet.tagId) {
                    e.currentTarget = {
                        id: _dataSet.tagId
                    };
                } else {
                    e.currentTarget = {
                        dataset: _dataSet
                    };
                }
            }
            
            var current = e.target.dataset.src; //这里获取到的是一张本地的图片

            uni.previewImage({
                current: current,
                //需要预览的图片链接列表
                urls: this.banner_detail //当前显示图片的链接
            });
        },

        getDetail() {
            //详情接口
            var json = {
                id: this.id
            };
            Api.bannerDetail(json).then((res) => {
                console.log(res);

                if (res.code == 1) {
                    this.setData({
                        banner_detail: res.data
                    });
                } else {
                    uni.showToast({
                        title: 'banner详情不存在',
                        icon: 'error',
                        duration: 2000
                    });
                    setTimeout(function () {
                        uni.navigateBack();
                    }, 2000);
                }
            });
        }
    }
};
</script>
<style>
@import './index.css';
</style>
